package com.woniu.his.sms.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.his.result.Result;
import com.woniu.his.sms.client.SmsDeptQueryClient;
import com.woniu.his.sms.client.param.FindDeptParam;
import com.woniu.his.sms.client.result.DeptResult;
import com.woniu.his.sms.client.result.PageDeptResult;
import com.woniu.his.sms.service.DeptService;
import com.woniu.his.sms.service.dto.DeptDto;
import com.woniu.his.sms.service.dto.PageDeptDto;
import com.woniu.his.sms.service.param.FindDeptServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/sms")
public class SmsDeptQueryApiImpl implements SmsDeptQueryClient {

    @Resource
    private DeptService deptService;

    @Override
    public Result<PageDeptResult> findDept(FindDeptParam param) {

        log.info("查寻科室的条件传的参数：{}", param);
        FindDeptServiceParam serviceParam = BeanUtil.copyProperties(param, FindDeptServiceParam.class);
        PageDeptDto pageDeptDto = deptService.findDept(serviceParam);
        PageDeptResult result = BeanUtil.copyProperties(pageDeptDto, PageDeptResult.class);
        return Result.getInstance(PageDeptResult.class).setData(result);
    }

    /**
     * 找到所有科室
     *
     * @return {@link Result}<{@link List}<{@link DeptResult}>>
     */
    @Override
    public Result<List<DeptResult>> FindAllDept() {

        log.info("执行查询全部科室的接口");
        List<DeptDto> deptDtos = deptService.FindAllDept();
        List<DeptResult> results=BeanUtil.copyToList(deptDtos,DeptResult.class);
        return Result.getInstanceList(DeptResult.class).setData(results);
    }

    @Override
    public Result<DeptResult> findDeptById(Integer id) {

        log.info("传回来的科室ID是：{}",id);
        DeptDto deptDto= deptService.findDeptById(id);
        DeptResult result=BeanUtil.copyProperties(deptDto,DeptResult.class);
        return Result.getInstance(DeptResult.class).setData(result);
    }
}
